function k = H2Derivs(t,u,params)

Nx = params{1};
Ny = params{2};
Jx = params{3};
Jy = params{4};
DriveFlag = params{5};
Drive = params{6};

if DriveFlag
    [ft, fx, fy] = Drive(t);
else
    ft = 0;
    fx = 0;
    fy = 0;
end

Nt = Nx*Ny;

cc = ((sqrt(3)*pi) -(9*log(3)) +18)/18;


ux = reshape(u(     1:  Nt),Nx,Ny); 
uy = reshape(u(1*Nt+1:2*Nt),Nx,Ny); 
T  = reshape(u(2*Nt+1:3*Nt),Nx,Ny); 
P  = reshape(u(3*Nt+1:4*Nt),Nx,Ny); 
B  = reshape(u(4*Nt+1:5*Nt),Nx,Ny); 

k = u;


uxx = Jx*SpectralGrad(ux,'fourier',1);
uyx = Jx*SpectralGrad(uy,'fourier',1);
Tx  = Jx*SpectralGrad( T,'fourier',1);
Px  = Jx*SpectralGrad( P,'fourier',1);
Bx  = Jx*SpectralGrad( B,'fourier',1);

uxy = Jy*SpectralGrad(ux,'fourier',2);
uyy = Jy*SpectralGrad(uy,'fourier',2);
Ty  = Jy*SpectralGrad( T,'fourier',2);
Py  = Jy*SpectralGrad( P,'fourier',2);
By  = Jy*SpectralGrad( B,'fourier',2);


m11=(2+ux.^2+uy.^2).*((-3).*T.^3.*ux+(-4).*B.*ux.*(1+uy.^2)+(-2).*P.* ...
  uy.*(2+(-1).*ux.^2+uy.^2));
m12=(-1).*(2+ux.^2+uy.^2).*((3.*T.^3+(-4).*B.*(1+ux.^2)).*uy+2.*P.* ...
  ux.*(2+ux.^2+(-1).*uy.^2));
m13=(-6).*T.^2.*(1+ux.^2+uy.^2).*(2+ux.^2+uy.^2);
%m14=0;
%m15=0;

m21=(1/2).*(1+ux.^2+uy.^2).^(-1).*(2+ux.^2+uy.^2).*(3.*T.^3.*(1+ux.^2+ ...
  uy.^2).*(2+ux.^2+2.*uy.^2)+2.*P.*ux.*uy.*(2+3.*(ux.^2+ux.^4)+ ...
  uy.^2+(-3).*uy.^4)+4.*B.*(ux.^4.*(1+(-3).*uy.^2)+2.*(1+uy.^2)+(-3) ...
  .*ux.^2.*((-1)+uy.^4)));
m22=(-1/2).*(1+ux.^2+uy.^2).^(-1).*(2+ux.^2+uy.^2).*(ux.*uy.*(3.* ...
  T.^3.*(1+ux.^2+uy.^2)+(-4).*B.*(1+ux.^2).*(1+3.*ux.^2+3.*uy.^2))+ ...
  2.*P.*((-4)+3.*ux.^4+3.*ux.^6+(-6).*uy.^2+(-4).*uy.^4+(-1).* ...
  ux.^2.*(4+3.*(uy.^2+uy.^4))));
%m23=0;
m24=2.*uy.*(2+ux.^2+uy.^2).*(2+3.*ux.^2+uy.^2);
m25=4.*(ux+ux.^3).*(2+ux.^2+uy.^2);

m31=(1/2).*(1+ux.^2+uy.^2).^(-1).*(2+ux.^2+uy.^2).*((-1).*ux.*uy.*(3.* ...
  T.^3.*(1+ux.^2+uy.^2)+4.*B.*(1+uy.^2).*(1+3.*ux.^2+3.*uy.^2))+2.* ...
  P.*(3.*ux.^2.*(2+uy.^2)+ux.^4.*(4+3.*uy.^2)+(-1).*(1+uy.^2).*((-4) ...
  +3.*uy.^4)));
m32=(1/2).*(1+ux.^2+uy.^2).^(-1).*(2+ux.^2+uy.^2).*(3.*T.^3.*(1+ux.^2+ ...
  uy.^2).*(2+2.*ux.^2+uy.^2)+4.*B.*((-2).*(1+ux.^2)+3.*((-1)+ux.^4) ...
  .*uy.^2+((-1)+3.*ux.^2).*uy.^4)+2.*P.*ux.*uy.*(2+ux.^2+(-3).* ...
  ux.^4+3.*(uy.^2+uy.^4)));
%m33=0;
m34=2.*ux.*(2+ux.^2+uy.^2).*(2+ux.^2+3.*uy.^2);
m35=(-4).*(2+ux.^2+uy.^2).*(uy+uy.^3);

m41=(-1/3).*T.^(-4).*(2+ux.^2+uy.^2).*(3.*T.^3.*uy.*(2.*P.*ux.*(ux+( ...
  -1).*uy).*uy.*(ux+uy)+T.^3.*(1+uy.^2))+4.*B.*(1+uy.^2).*((-3).* ...
  T.^3.*(1+ux.^2).*uy+cc.*ux.*((-3).*T.^3.*ux.*uy+2.*P.*(2+ux.^2+ ...
  uy.^2)))+cc.*P.*(4.*P.*uy.*((-1).*ux.^4+(2+uy.^2).^2)+3.*T.^3.* ...
  ux.*(6+uy.^2+(-2).*uy.^4+ux.^2.*(5+2.*uy.^2))));
m42=(-1/3).*T.^(-4).*(2+ux.^2+uy.^2).*(3.*T.^3.*ux.*(T.^3.*(1+ux.^2)+ ...
  4.*B.*(1+ux.^2).*(1+uy.^2)+2.*P.*ux.*uy.*((-1).*ux.^2+uy.^2))+cc.* ...
  (12.*B.*T.^3.*ux.*(1+ux.^2).*uy.^2+4.*P.^2.*ux.*((2+ux.^2).^2+(-1) ...
  .*uy.^4)+P.*uy.*((-8).*B.*(1+ux.^2).*(2+ux.^2+uy.^2)+3.*T.^3.*(6+ ...
  ux.^2+(-2).*ux.^4+(5+2.*ux.^2).*uy.^2))));
%m43=0;
m44=(-2).*cc.*T.^(-1).*(1+ux.^2+uy.^2).*(2+ux.^2+uy.^2).^2;
%m45=0;

m51=(1/3).*T.^(-4).*(2+ux.^2+uy.^2).*(16.*B.^2.*cc.*ux.*(1+uy.^2).*(2+ ...
  ux.^2+uy.^2)+3.*T.^3.*(T.^3.*ux.*(2+ux.^2+3.*uy.^2)+2.*P.*uy.*((1+ ...
  cc).*ux.^4+(2+uy.^2).*(2+(1+cc).*uy.^2)+(-2).*ux.^2.*((-2)+cc+(1+ ...
  cc).*uy.^2)))+2.*B.*(6.*T.^3.*ux.*uy.^2.*((-1).*ux.^2+uy.^2)+cc.*( ...
  3.*T.^3.*ux.*(6+7.*uy.^2+2.*uy.^4+ux.^2.*(3+(-2).*uy.^2))+4.*P.* ...
  uy.*((-1).*ux.^4+(2+uy.^2).^2))));
m52=(-1/3).*T.^(-4).*(2+ux.^2+uy.^2).*(16.*B.^2.*cc.*(1+ux.^2).*uy.*( ...
  2+ux.^2+uy.^2)+2.*B.*((-4).*cc.*P.*ux.*(2+ux.^2).^2+(-3).*T.^3.*( ...
  6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 ...
  ux.^2).*(1+uy.^2).*(2+ux.^2+uy.^2)+3.*T.^3.*(T.^3.*(2+ux.^4+3.* ...
  uy.^2+uy.^4+ux.^2.*(3+2.*uy.^2))+2.*P.*ux.*uy.*(4+(1+cc).*ux.^4+( ...
  -2).*((-2)+cc).*uy.^2+(1+cc).*uy.^4+(-2).*ux.^2.*((-2)+uy.^2+cc.*( ...
  (-1)+uy.^2))))+(-2).*B.*(6.*T.^3.*ux.^2.*uy.^2.*(ux.^2+(-1).* ...
  uy.^2)+cc.*(4.*P.*ux.*uy.*(2.*ux.^2+ux.^4+(-1).*uy.^2.*(2+uy.^2))+ ...
  3.*T.^3.*(ux.^4.*(3+2.*uy.^2)+ux.^2.*(9+10.*uy.^2+(-2).*uy.^4)+3.* ...
  (2+3.*uy.^2+uy.^4))))).*uyy);



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Dux = (b5.*(m25.*m34.*m42+(-1).*m24.*m35.*m42+(-1).*m25.*m32.*m44+m22.* ...
  m35.*m44)+b3.*m25.*m44.*m52+(-1).*b2.*m35.*m44.*m52+b3.*m24.*m42.* ...
  m55+(-1).*b2.*m34.*m42.*m55+(-1).*b3.*m22.*m44.*m55+b2.*m32.*m44.* ...
  m55+b4.*((-1).*m25.*m34.*m52+m24.*m35.*m52+(-1).*m24.*m32.*m55+ ...
  m22.*m34.*m55)).*(m22.*m35.*m44.*m51+(-1).*m21.*m35.*m44.*m52+ ...
  m25.*(m34.*m42.*m51+(-1).*m32.*m44.*m51+(-1).*m34.*m41.*m52+m31.* ...
  m44.*m52)+m22.*m34.*m41.*m55+(-1).*m21.*m34.*m42.*m55+(-1).*m22.* ...
  m31.*m44.*m55+m21.*m32.*m44.*m55+m24.*((-1).*m35.*m42.*m51+m35.* ...
  m41.*m52+(-1).*m32.*m41.*m55+m31.*m42.*m55)).^(-1);

Duy = (b5.*(m25.*m34.*m41+(-1).*m24.*m35.*m41+(-1).*m25.*m31.*m44+m21.* ...
  m35.*m44)+((-1).*b4.*m25.*m34+b4.*m24.*m35+b3.*m25.*m44+(-1).*b2.* ...
  m35.*m44).*m51+((-1).*b4.*m24.*m31+b4.*m21.*m34+b3.*m24.*m41+(-1) ...
  .*b2.*m34.*m41+(-1).*b3.*m21.*m44+b2.*m31.*m44).*m55).*(m35.*( ...
  m24.*m42.*m51+(-1).*m22.*m44.*m51+(-1).*m24.*m41.*m52+m21.*m44.* ...
  m52)+m25.*((-1).*m34.*m42.*m51+m32.*m44.*m51+m34.*m41.*m52+(-1).* ...
  m31.*m44.*m52)+(m24.*m32.*m41+(-1).*m22.*m34.*m41+(-1).*m24.*m31.* ...
  m42+m21.*m34.*m42+m22.*m31.*m44+(-1).*m21.*m32.*m44).*m55).^(-1); ...
  

DT =  m13.^(-1).*(m35.*((-1).*m24.*m42.*m51+m22.*m44.*m51+m24.*m41.*m52+ ...
  (-1).*m21.*m44.*m52)+m25.*(m34.*m42.*m51+(-1).*m32.*m44.*m51+(-1) ...
  .*m34.*m41.*m52+m31.*m44.*m52)+((-1).*m24.*m32.*m41+m22.*m34.*m41+ ...
  m24.*m31.*m42+(-1).*m21.*m34.*m42+(-1).*m22.*m31.*m44+m21.*m32.* ...
  m44).*m55).^(-1).*(b5.*(m25.*m34+(-1).*m24.*m35).*(m12.*m41+(-1).* ...
  m11.*m42)+b5.*((-1).*m12.*m25.*m31+m11.*m25.*m32+m12.*m21.*m35+( ...
  -1).*m11.*m22.*m35).*m44+b1.*m25.*m34.*m42.*m51+(-1).*b1.*m24.* ...
  m35.*m42.*m51+b3.*m12.*m25.*m44.*m51+(-1).*b1.*m25.*m32.*m44.*m51+ ...
  (-1).*b2.*m12.*m35.*m44.*m51+b1.*m22.*m35.*m44.*m51+(-1).*b1.* ...
  m25.*m34.*m41.*m52+b1.*m24.*m35.*m41.*m52+(-1).*b3.*m11.*m25.* ...
  m44.*m52+b1.*m25.*m31.*m44.*m52+b2.*m11.*m35.*m44.*m52+(-1).*b1.* ...
  m21.*m35.*m44.*m52+(-1).*b4.*(m25.*m34+(-1).*m24.*m35).*(m12.*m51+ ...
  (-1).*m11.*m52)+b4.*((-1).*m12.*m24.*m31+m11.*m24.*m32+m12.*m21.* ...
  m34+(-1).*m11.*m22.*m34).*m55+(b3.*(m12.*m24.*m41+(-1).*m11.*m24.* ...
  m42+(-1).*m12.*m21.*m44+m11.*m22.*m44)+b2.*((-1).*m12.*m34.*m41+ ...
  m11.*m34.*m42+m12.*m31.*m44+(-1).*m11.*m32.*m44)+b1.*((-1).*m24.* ...
  m32.*m41+m22.*m34.*m41+m24.*m31.*m42+(-1).*m21.*m34.*m42+(-1).* ...
  m22.*m31.*m44+m21.*m32.*m44)).*m55);

DP =  (m35.*(m24.*m42.*m51+(-1).*m22.*m44.*m51+(-1).*m24.*m41.*m52+m21.* ...
  m44.*m52)+m25.*((-1).*m34.*m42.*m51+m32.*m44.*m51+m34.*m41.*m52+( ...
  -1).*m31.*m44.*m52)+(m24.*m32.*m41+(-1).*m22.*m34.*m41+(-1).*m24.* ...
  m31.*m42+m21.*m34.*m42+m22.*m31.*m44+(-1).*m21.*m32.*m44).*m55).^( ...
  -1).*(b5.*((-1).*m25.*m32.*m41+m22.*m35.*m41+m25.*m31.*m42+(-1).* ...
  m21.*m35.*m42)+(-1).*(b3.*m25+(-1).*b2.*m35).*(m42.*m51+(-1).* ...
  m41.*m52)+((-1).*b3.*m22.*m41+b2.*m32.*m41+b3.*m21.*m42+(-1).*b2.* ...
  m31.*m42).*m55+b4.*(m25.*m32.*m51+(-1).*m22.*m35.*m51+(-1).*m25.* ...
  m31.*m52+m21.*m35.*m52+m22.*m31.*m55+(-1).*m21.*m32.*m55));

DB = (b5.*(m24.*m32.*m41+(-1).*m22.*m34.*m41+(-1).*m24.*m31.*m42+m21.* ...
  m34.*m42+m22.*m31.*m44+(-1).*m21.*m32.*m44)+((-1).*b4.*m24.*m32+ ...
  b4.*m22.*m34+b3.*m24.*m42+(-1).*b2.*m34.*m42+(-1).*b3.*m22.*m44+ ...
  b2.*m32.*m44).*m51+(b4.*m24.*m31+(-1).*b4.*m21.*m34+(-1).*b3.* ...
  m24.*m41+b2.*m34.*m41+b3.*m21.*m44+(-1).*b2.*m31.*m44).*m52).*( ...
  m35.*(m24.*m42.*m51+(-1).*m22.*m44.*m51+(-1).*m24.*m41.*m52+m21.* ...
  m44.*m52)+m25.*((-1).*m34.*m42.*m51+m32.*m44.*m51+m34.*m41.*m52+( ...
  -1).*m31.*m44.*m52)+(m24.*m32.*m41+(-1).*m22.*m34.*m41+(-1).*m24.* ...
  m31.*m42+m21.*m34.*m42+m22.*m31.*m44+(-1).*m21.*m32.*m44).*m55).^( ...
  -1);


k(     1:  Nt) = Dux(:);
k(1*Nt+1:2*Nt) = Duy(:);
k(2*Nt+1:3*Nt) = DT(:);
k(3*Nt+1:4*Nt) = DP(:);
k(4*Nt+1:5*Nt) = DB(:);

end
